<html>
<head><meta charset="utf-8"><title>Arbitrary-width integer types: LLVM support! · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html">Arbitrary-width integer types: LLVM support!</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="194947199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/194947199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#194947199">(Apr 22 2020 at 15:20)</a>:</h4>
<p><a href="http://blog.llvm.org/2020/04/the-new-clang-extint-feature-provides.html" title="http://blog.llvm.org/2020/04/the-new-clang-extint-feature-provides.html">http://blog.llvm.org/2020/04/the-new-clang-extint-feature-provides.html</a></p>



<a name="194947249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/194947249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#194947249">(Apr 22 2020 at 15:21)</a>:</h4>
<p>Here's hoping we can wire that up in Rust.</p>



<a name="194948042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/194948042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#194948042">(Apr 22 2020 at 15:27)</a>:</h4>
<p>(hanna shared more details on discord (#design room) but this is mostly news for clang/C, it's always been supported in LLVM IR)</p>



<a name="194956415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/194956415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sebastian Malton <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#194956415">(Apr 22 2020 at 16:25)</a>:</h4>
<p>I assume that <a href="https://github.com/rust-lang/rfcs/pull/2581" title="https://github.com/rust-lang/rfcs/pull/2581">https://github.com/rust-lang/rfcs/pull/2581</a> will use this feature in LLVM</p>



<a name="194962316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/194962316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#194962316">(Apr 22 2020 at 17:10)</a>:</h4>
<p>tried performing division using <code>_ExtInt(8192)</code>, and clang ICE with "error in backend: Unsupported library call operation!" <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<a name="194962713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/194962713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#194962713">(Apr 22 2020 at 17:13)</a>:</h4>
<p><code>_ExtInt(128)</code> is the highest type supporting <code>/</code> and <code>%</code>, as expected.</p>



<a name="194972960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/194972960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#194972960">(Apr 22 2020 at 18:32)</a>:</h4>
<p>While it's always been theoretically supported in IR, it'll probably mean it has fewer rough edge, which is nice.</p>



<a name="194973228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/194973228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#194973228">(Apr 22 2020 at 18:34)</a>:</h4>
<p>I often wish we could have <code>u63</code> and such -- we have a ton of APIs that take a usize where you're prohibited from setting the high bit</p>



<a name="194974758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/194974758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#194974758">(Apr 22 2020 at 18:46)</a>:</h4>
<p>there were some suggestions regarding using const generics for arbitrary-width integers, though I can't remember how nice the APIs were</p>



<a name="195117546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195117546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195117546">(Apr 23 2020 at 20:48)</a>:</h4>
<p>Yep, there's a ton of low-level data structures that could benefit from it too. Like taking 9 bits out of a virtual address to index a page table.</p>



<a name="195118552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195118552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195118552">(Apr 23 2020 at 20:57)</a>:</h4>
<p>I'm dealing with many u48 and u40 values lately.</p>



<a name="195118716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195118716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195118716">(Apr 23 2020 at 20:58)</a>:</h4>
<p>And in one case, a u34 value...</p>



<a name="195119173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195119173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195119173">(Apr 23 2020 at 21:02)</a>:</h4>
<p>The PNG spec says that image dimensions are supposed to be the equivalent of what Rust would call <code>NonZeroU31</code>. And a lot of MMIO would benefit from some sort of bitfields struct support combined with arbitrary width integers.</p>



<a name="195119616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195119616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195119616">(Apr 23 2020 at 21:05)</a>:</h4>
<p>I believe this clang extension is completely unrelated to bitfields.</p>



<a name="195119824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195119824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195119824">(Apr 23 2020 at 21:07)</a>:</h4>
<blockquote>
<p>_ExtInt types are bit-aligned to the next greatest power-of-2 up to 64 bits</p>
</blockquote>
<p>So basically these types still use up the same amount of memory as normal integers but have operations on them effectively automatically truncated to a certain bit width.</p>



<a name="195122232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195122232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195122232">(Apr 23 2020 at 21:33)</a>:</h4>
<p>That would make them helpful for implementing bitfield semantics, though.</p>



<a name="195128469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195128469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195128469">(Apr 23 2020 at 22:42)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> Hm, I don't see how that's true? You'd (if I understand correctly) not be able to use these for bit fields because <code>a: u1, b: u1</code> takes up two bytes still</p>



<a name="195128645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195128645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195128645">(Apr 23 2020 at 22:44)</a>:</h4>
<p>It might have to be kinda jiggered a bit on the Rust side of things, where you have a setter that takes a <code>u3</code> or something and then stores it in a <code>u16</code>or whatever by upcasting it and then shifting it into place and such.</p>



<a name="195128652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195128652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195128652">(Apr 23 2020 at 22:44)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> In Rust yes. I meant that with C-style bitfields, you could write <code>_ExtInt(5) fieldname: 5;</code> and you'd have a field that not only takes up five bits, but operates as a five-bit number type.</p>



<a name="195128694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195128694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195128694">(Apr 23 2020 at 22:45)</a>:</h4>
<p>That would need more wiring up to work in Rust, not least of which, having bitfield support. :)</p>



<a name="195128761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195128761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195128761">(Apr 23 2020 at 22:46)</a>:</h4>
<p><code>no-ref fieldname: u5</code> ;)</p>



<a name="195137706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Arbitrary-width%20integer%20types%3A%20LLVM%20support%21/near/195137706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sebastian Malton <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Arbitrary-width.20integer.20types.3A.20LLVM.20support!.html#195137706">(Apr 24 2020 at 01:08)</a>:</h4>
<p>I sort of like how zig did this, they allow references to bitfields by encoding the offsets in the type</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>